package com.unisound.tracelog.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.unisound.tracelog.server.mapper.TraceLogTagMapper;
import com.unisound.tracelog.server.model.entity.TraceLogTag;
import com.unisound.tracelog.server.service.TraceLogTagService;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Service
public class TraceLogTagServiceImpl extends ServiceImpl<TraceLogTagMapper, TraceLogTag> implements TraceLogTagService {

    @Override
    public void clearExpiredSpan() {
        long days = 14;
        LocalDate localDate = LocalDate.now().minusDays(days);
        LocalDateTime localDateTime = localDate.atTime(4, 0);

        LambdaQueryWrapper<TraceLogTag> wrapper = new LambdaQueryWrapper<>();
        wrapper.lt(TraceLogTag::getCreateTime, localDateTime);

        remove(wrapper);
    }

}
